<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/11
 * Time: 16:24
 */
$link=mysqli_connect('localhost','ni','123456')or die(json_encode(array('result'=>'connect database fail!')));

mysqli_select_db($link,'ajaxdb')or die(json_encode(array('result'=>'select database error')));

$sql_select='select * from ys3181msg order by `id` asc';

$res=mysqli_query($link,$sql_select);

$userArr=array();

while ($rows=mysqli_fetch_assoc($res)){
    array_push($userArr,array($rows['id'],$rows['username']));
}

if ($userArr!=''){
    echo json_encode(array('result'=>'select username success','userArr'=>$userArr));
}else{
    echo json_encode(array('result'=>'select username error!'));
}

mysqli_close($link);